#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

const short MAX_ROTOR_SIZE = 26;
short g_rotor1[MAX_ROTOR_SIZE];
short g_rotor2[MAX_ROTOR_SIZE];
short g_rotor3[MAX_ROTOR_SIZE];

string findPlainText(string& encrypted, short rotorSize);

// #define READ_FILE

int main()
{
#ifdef READ_FILE
    ifstream readIn("1009.input");
	if (!readIn)
	{
		readIn.open("../1009.input");
	}
#else
#define readIn cin
#endif

    short rotorSize;
    int caseCount;
    string testCase;
    string plainText;

    int count = 0;
    while (true)
    {
        readIn >> rotorSize;
        if (rotorSize == 0)
        {
            break;
        }
        count++;

        memset(g_rotor1, 0, sizeof(g_rotor1));
        memset(g_rotor2, 0, sizeof(g_rotor2));
        memset(g_rotor3, 0, sizeof(g_rotor3));

        char ch;
        for (int i = 0; i < rotorSize; i++)
        {
            readIn >> ch;
            g_rotor1[ch-'A'] = 'A' + i - ch;
        }
        for (int i = 0; i < rotorSize; i++)
        {
            readIn >> ch;
            g_rotor2[ch-'A'] = 'A' + i - ch;
        }
        for (int i = 0; i < rotorSize; i++)
        {
            readIn >> ch;
            g_rotor3[ch-'A'] = 'A' + i - ch;
        }

        readIn >> caseCount;
        
        if (count > 1)
        {
            cout << endl;
        }
        cout << "Enigma " << count << ':' << endl;
        for (int i = 0; i < caseCount; i++)
        {
            readIn >> testCase;
            plainText = findPlainText(testCase, rotorSize);
            cout << plainText << endl;
        }
    }
#ifdef READ_FILE
    readIn.close();
#endif
    return 0;
}


string findPlainText(string& encrypted, short rotorSize)
{
    int offset1 = 0;
    int offset2 = 0;
    int offset3 = 0;

    string plain(encrypted);
    short index;


    for (int i = 0; i < encrypted.length(); i++)
    {
        index = encrypted[i] - 'A';

        if (index - offset3 < 0) index += g_rotor3[index - offset3 + rotorSize];
        else if (index - offset3 >= rotorSize) index += g_rotor3[index - offset3 - rotorSize];
        else index += g_rotor3[index - offset3];

        if (index < 0) index += rotorSize;
        else if (index >= rotorSize) index -= rotorSize;
        
        if (index - offset2 < 0) index += g_rotor2[index - offset2 + rotorSize];
        else if (index - offset2 >= rotorSize) index += g_rotor2[index - offset2 - rotorSize];
        else index += g_rotor2[index - offset2];
        
        if (index < 0) index += rotorSize;
        else if (index >= rotorSize) index -= rotorSize;
        
        if (index - offset1 < 0) index += g_rotor1[index - offset1 + rotorSize];
        else if (index - offset1 >= rotorSize) index += g_rotor1[index - offset1 - rotorSize];
        else index += g_rotor1[index - offset1];

        if (index < 0) index += rotorSize;
        else if (index >= rotorSize) index -= rotorSize;

        plain[i] = 'a' + index;

        offset1++;
        if (offset1 == rotorSize)
        {
            offset1 = 0;
            offset2++;
            if (offset2 == rotorSize)
            {
                offset2 = 0;
                offset3++;
                if (offset3 == rotorSize)
                {
                    offset3 = 0;
                }
            }
        }

    } // for (int i = 0; i < plain.size(); i++)

    return plain;
}

